﻿using UnityEngine;

namespace Room
{
    class FieldBossAIStateDeath : FieldBossAIStateBase
    {
        GameObject obj;
        protected override void OnEnter()
        {
            if(obj!=null)
            {
                GameObjectPoolManager.Instance.Unspawn(obj);
            }
            obj = GameObjectPoolManager.Instance.Spawn(RoomField.particleDieAb,CommonMethod.GetAssetNameFromAssetBundleName(RoomField.particleDieAb));
            obj.transform.SetParent(controller.owner.transform);
            obj.transform.localScale = Vector3.one;
            obj.transform.localPosition = Vector3.zero;
            obj.transform.SetParent(controller.owner.transform.parent);
            obj.SetActive(true);
            curTimer = 0f;
            timer = 1f;
        }

        float timer = 1f;
        float curTimer = 0f;

        protected override void OnTick()
        {
            base.OnTick();
            curTimer += Time.deltaTime;
            if (curTimer >= timer)
            {
                curTimer = 0;
                controller.SwitchState(FieldBossAIState.Normal);
            }
        }

        protected override void OnLeave()
        {
            GameObjectPoolManager.Instance.Unspawn(obj);
            
        }
    }
}
